//
//  OperationUsedCell.m
//  MonitoringNetwork
//
//  Created by admin on 2017/12/22.
//  Copyright © 2017年 wtmcxlm. All rights reserved.
//

#import "OperationUsedCell.h"

@interface OperationUsedCell()
@property (nonatomic,strong)UILabel *usedRateLabel;
@property (nonatomic,strong)UILabel *usedNumLabel;
@end

@implementation OperationUsedCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
//        [self setUpUI];
    }
    return self;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI
{
    UIView *backView = [UIView new];
    backView.backgroundColor = [UIColor colorWithRed:0.97f green:0.97f blue:0.97f alpha:1.00f];
    [self addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(self);
        make.height.mas_equalTo(11);
    }];
    UILabel *label4 = [UILabel LabelWithFont:TitleLagerFontSize andColor:TitleColor andTextAlignment:left andString:@"使用数"];
    [self addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(33);
        make.bottom.mas_equalTo(self.mas_top).offset(36+11);
    }];
    UILabel *label5 = [UILabel LabelWithFont:TitleLagerFontSize andColor:TitleColor andTextAlignment:left andString:@"使用率"];
    [self addSubview:label5];
    [label5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_centerX).offset(0);
        make.bottom.mas_equalTo(self.mas_top).offset(36+11);
    }];
    
    _usedNumLabel = [UILabel LabelWithFont:MaxFontSize andColor:NumColor andTextAlignment:left andString:@"0"];
    [self addSubview:_usedNumLabel];
    [_usedNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(33);
        make.bottom.mas_equalTo(self.mas_top).offset(89+11);
    }];
    _usedRateLabel = [UILabel LabelWithFont:MaxFontSize andColor:NumColor andTextAlignment:left andString:@"0"];
    [self addSubview:_usedRateLabel];
    [_usedRateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.mas_top).offset(89+11);
        make.left.mas_equalTo(self.mas_centerX).offset(0);
    }];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    if (_dic) {
        
        int totalNum = [_dic[@"totalCarNum"] intValue];
        int useNum = [_dic[@"useCarNum"] intValue];
        NSString *str = @"%";
        double percent;
        if (totalNum == 0) {
            percent = 0;
        }else{
            percent = (useNum*1.00f)/(totalNum*1.00f);
        }
        _usedNumLabel.text = [NSString separatedDigitStringWithStr:[NSString stringWithFormat:@"%d",useNum]];
        _usedRateLabel.text = [NSString stringWithFormat:@"%.2lf%@",percent*100,str];
    }
}

@end
